import asyncio
import websockets

async def handle_client(websocket, path):
    try:
        async for message in websocket:
            if message == "ping":
                await websocket.send("pong")
            else:
                print(f"Received: {message}")
    except websockets.ConnectionClosed:
        pass

async def main():
    async with websockets.serve(handle_client, "localhost", 8765):
        print("Server is running...")
        await asyncio.Future()  # run forever

if __name__ == "__main__":
    asyncio.run(main())